package com.ruoyi.quartz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quartz.domain.StockDaily;
import com.ruoyi.quartz.service.IStockDailyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票日行情Controller
 * 
 * @author ruoyi
 * @date 2023-11-28
 */
@Controller
@RequestMapping("/finance/day")
public class StockDailyController extends BaseController
{
    private String prefix = "finance/day";

    @Autowired
    private IStockDailyService stockDailyService;

    @RequiresPermissions("finance:day:view")
    @GetMapping()
    public String day()
    {
        return prefix + "/day";
    }

    /**
     * 查询股票日行情列表
     */
    @RequiresPermissions("finance:day:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockDaily stockDaily)
    {
        startPage();
        List<StockDaily> list = stockDailyService.selectStockDailyList(stockDaily);
        return getDataTable(list);
    }

    /**
     * 导出股票日行情列表
     */
    @RequiresPermissions("finance:day:export")
    @Log(title = "股票日行情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockDaily stockDaily)
    {
        List<StockDaily> list = stockDailyService.selectStockDailyList(stockDaily);
        ExcelUtil<StockDaily> util = new ExcelUtil<StockDaily>(StockDaily.class);
        return util.exportExcel(list, "股票日行情数据");
    }

    /**
     * 新增股票日行情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存股票日行情
     */
    @RequiresPermissions("finance:day:add")
    @Log(title = "股票日行情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockDaily stockDaily)
    {
        return toAjax(stockDailyService.insertStockDaily(stockDaily));
    }

    /**
     * 修改股票日行情
     */
    @RequiresPermissions("finance:day:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StockDaily stockDaily = stockDailyService.selectStockDailyById(id);
        mmap.put("stockDaily", stockDaily);
        return prefix + "/edit";
    }

    /**
     * 修改保存股票日行情
     */
    @RequiresPermissions("finance:day:edit")
    @Log(title = "股票日行情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockDaily stockDaily)
    {
        return toAjax(stockDailyService.updateStockDaily(stockDaily));
    }

    /**
     * 删除股票日行情
     */
    @RequiresPermissions("finance:day:remove")
    @Log(title = "股票日行情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockDailyService.deleteStockDailyByIds(ids));
    }
}
